<template>
  <div class="discovery-container">
    <!-- 轮播图 -->
    <el-carousel class="" :interval="4000" type="card">
      <el-carousel-item v-for="(item,index) in banners" :key="index">
        <img :src="item.pic" alt="" />
      </el-carousel-item>
    </el-carousel>
    <!-- 推荐歌单 -->
    <div class="recommend">
      <h3 class="title">
        推荐歌单
      </h3>
      <div class="items">
        <div 
         class="item" 
         v-for="(item,index) in lists" 
         :key="index"
         @click="toplaylist(item.id)"
         >
          <div class="img-wrap">
            <div class="desc-wrap">
              <span class="desc">{{item.description}}</span>
            </div>
            <img :src="item.coverImgUrl" alt="" />
            <span class="iconfont icon-play"></span>
          </div>
          <p class="name">{{item.name}}</p>
        </div>
      </div>
    </div>
    <!-- 最新音乐 -->
    <div class="news">
      <h3 class="title">
        最新音乐
      </h3>
      <div class="items">
        <div class="item" v-for="(item,index) in newSongs" :key="index">
          <div class="img-wrap">
            <img :src="item.album.blurPicUrl" alt="" />
            <span @click="playMusic(item.id)" class="iconfont icon-play"></span>
          </div>
          <div class="song-wrap">
            <div class="song-name">{{item.name}}</div>
            <div class="singer">{{item.artists[0].name}}</div>
          </div>
        </div>
      </div>
    </div>
    <!-- 推荐MV -->
    <div class="mvs">
      <h3 class="title">推荐MV</h3>
      <div class="items">
        <div @click="tomv(item.id)" class="item" v-for="(item,index) in mvs" :key="index">
          <div class="img-wrap">
            <img :src="item.cover" alt="" />
            <span class="iconfont icon-play"></span>
            <div class="num-wrap">
              <div class="iconfont icon-play"></div>
              <div class="num">{{item.playCount}}</div>
            </div>
          </div>
          <div class="info-wrap">
            <div class="name">{{item.name}}</div>
            <div class="singer">{{item.artistName}}</div>
          </div>
        </div>
      </div>
    </div> 
  </div>
</template>

<script>
import getHomeInfo from '../utils/discovery'
export default {
  name: 'discovery',
  data(){
    return{
      banners:[],
      lists:[],
      newSongs:[],
      mvs:[]
    }
  },
  created(){
    getHomeInfo.getBanners().then(res => {
      this.banners = res.data.data.blocks[0].extInfo.banners;
      console.log(res.data.data);
    })
    getHomeInfo.getHotPlaylist().then(res => {
      this.lists = res.data.playlists;
    })
    getHomeInfo.getHotSongs().then(res => {
      for(let i = 0; i < 10; i++){
        let song= res.data.data[i];
        this.newSongs.push(song);
      }
    })
    getHomeInfo.getHotMvs().then(res => {
      this.mvs = res.data.data;
      console.log(this.mvs);
      for(let i = 0;i < this.mvs.length;i++){
        if(this.mvs[i].playCount > 100000){
          this.mvs[i].playCount = parseInt(this.mvs[i].playCount/10000) + '万';
        }
      }
    })
  },
  methods:{
    playMusic(id){
      discover.play(id).then(res => {
        console.log(res.data.data[0].url);
        this.$parent.musicUrl = res.data.data[0].url;
      })
    },
    toplaylist(id) {
      this.$router.push(`/playlist?q=${id}`);
    },
    tomv(id) {
      this.$router.push(`/mv?q=${id}`);
    },
  }
};
</script>

<style>

</style>
